#!/usr/bin/env python3
# -*- coding: utf-8 -*-


from django.db import models


# 用户信息
class CustomerModel(models.Model):

    name = models.CharField("客户名称", unique=True, max_length=40,
                            help_text='xxx公司')
    address = models.CharField("客户地址", max_length=60, default='',
                               help_text='xxx市xxx区...')
    trade = models.CharField('客户行业', default='', max_length=20,
                             help_text='比如，媒体服务')

    contact = models.CharField("联系人", max_length=20, help_text='比如，张三')
    telenumber = models.CharField('联系电话', max_length=40, blank=True,
                                  default='', help_text='比如，13807088888')
    email = models.CharField('联系邮箱', max_length=40, blank=True, default='',
                             help_text='比如，example@qq.com')

    saler = models.CharField('销售', max_length=10, help_text='比如，某某')
    level = models.CharField('客户级别', max_length=10, help_text='客户重要程度')
    remark = models.TextField("客户备注信息", max_length=1200, blank=True,
                              default='',
                              help_text='备注信息，比如，该客户使用国际出口..')

    creator = models.CharField('创建者', max_length=10, help_text='比如，某某')
    add_date = models.DateField('添加的时间', auto_now_add=True)
    modifier = models.CharField('修改者', max_length=10, help_text='比如，某某')
    mod_date = models.DateField('最后修改时间', auto_now=True)

    def __str__(self):
        return str(self.id)


# 线路订单信息
class CircuitOrderModel(models.Model):

    customer = models.ForeignKey(CustomerModel, on_delete=models.CASCADE)
    number = models.CharField("线路编号", unique=True, max_length=10,
                              blank=True, default='', help_text='比如，SI-002')

    type = models.CharField("线路订单类型", max_length=10,
                            help_text='比如，DIA业务')
    bandwith = models.CharField("业务带宽", max_length=10, blank=True,
                                default='', help_text='比如，2M')
    status = models.CharField('当前状态', max_length=10,
                              help_text='比如，测试中')

    local_isp = models.CharField("本地线路ISP", max_length=20,
                                 help_text='比如，中国联通')
    local_ip = models.TextField('本地线路IP信息', max_length=1000,
                                blank=True, default='',
                                help_text='比如，201.45.78.9/24 GW:201.45.78.1')
    hk_ip = models.TextField('业务IP或者VPN帐号', max_length=1000, blank=True,
                             default='',
                             help_text='比如，202.45.78.19/24 GW:202.45.78.11')

    router = models.CharField('路由器', max_length=20,
                              help_text='比如，RouterOS')
    mrtg = models.CharField('MRTG帐号', max_length=50, blank=True, default='',
                            help_text='MRTG帐号和密码, 比如，bjyb/bjyb123')
    start_test = models.CharField("开始测试日期", max_length=20,
                                  blank=True, default='',
                                  help_text='比如，2017-03-05')

    duration = models.CharField('签约时长', max_length=10, blank=True,
                                default='', help_text='比如，1年')
    start_billing = models.CharField("开始计费日期", max_length=20,
                                     blank=True, default='',
                                     help_text='比如，2017-11-20')
    remark = models.TextField("线路备注信息", max_length=1200, blank=True,
                              default='',
                              help_text='比如，该DIA线路有备份线路')

    attachment = models.FileField("附件", max_length=200,
                                  upload_to="circuit_order/",
                                  default="", blank=True,
                                  help_text="上传附件")

    creator = models.CharField('创建者', max_length=10, help_text='比如，某某')
    add_date = models.DateField('添加的时间', auto_now_add=True)
    modifier = models.CharField('修改者', max_length=10, help_text='比如，某某')
    mod_date = models.DateField('最后修改时间', auto_now=True)

    def __str__(self):
        return str(self.id)


# Ticket单
class TicketModel(models.Model):

    order = models.ForeignKey(CircuitOrderModel, on_delete=models.CASCADE)

    level = models.CharField("故障级别", max_length=10, help_text='比如，严重')
    handler = models.CharField('当前处理人', max_length=10,
                               help_text='比如，唐文君')
    status = models.CharField("当前状态", max_length=10, help_text='比如，处理中')

    describe = models.TextField("故障描述", max_length=1200,
                                default='', help_text='故障描述')
    start_time = models.CharField("客户报障日期", max_length=20,
                                  default='', help_text='比如，2017-11-20')
    end_time = models.CharField("处理完成日期", max_length=20,
                                blank=True, default='',
                                help_text='比如，2017-11-26')

    creator = models.CharField('创建者', max_length=10, help_text='比如，某某')
    add_date = models.DateField('添加的时间', auto_now_add=True)
    modifier = models.CharField('修改者', max_length=10, help_text='比如，某某')
    mod_date = models.DateField('最后修改时间', auto_now=True)

    def __str__(self):
        return str(self.id)


# ticket单处理的message信息
class TicketMessageModel(models.Model):

    ticket = models.ForeignKey(TicketModel, on_delete=models.CASCADE)

    message = models.TextField("处理信息记录", max_length=1000,
                               help_text="记录处理过程中的信息")

    add_date = models.DateTimeField("添加时间", auto_now_add=True)
    creator = models.CharField('创建者', max_length=10, help_text='比如，某某')
    mod_date = models.DateTimeField('最后修改时间', auto_now=True)
    modifier = models.CharField('修改者', max_length=10, help_text='比如，某某')

    def __str__(self):
        return str(self.id)
